<template>
  <div class="formBox">
    <!-- 卡片视图区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统设置</el-breadcrumb-item>
      <el-breadcrumb-item>人员管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20"></el-row>
    <el-card>
      <el-col :span="4">
        <el-button type="primary" @click="goAdd" size="medium">添加</el-button>
      </el-col>
      <!-- table表格区域 -->
      <el-table :data="tableData" label-width="auto" fit size="medium">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="userId" label="用户编号"></el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="eNum" label="工号"></el-table-column>
        <el-table-column prop="phone" label="电话号码"></el-table-column>
        <el-table-column prop="sex" label="性别"></el-table-column>
        <el-table-column prop="age" label="年龄"></el-table-column>
        <!-- <el-table-column prop="loginName" label="账号"></el-table-column>
        <el-table-column prop="password" label="密码"></el-table-column>-->
        <!-- <el-table-column prop="creationTime" label="创建日期"></el-table-column> -->
        <el-table-column prop="houseName" label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="getFormDataId(scope.row.id)"
            >查看</el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-edit"
              @click="goDelete(scope.row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </el-card>
    <!-- 弹出框 -->
    <el-dialog
      title="提示"
      :visible.sync="addCateDialogVisible"
      width="30%"
      @close="setRoleDialogClosed"
    >
      <el-form label-width="100px" class="demo-ruleForm" :model="addForm">
        <el-form-item label="用户编号：">
          <el-input v-model="addForm.userId"></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-input v-model="addForm.name"></el-input>
        </el-form-item>
        <el-form-item label="工号：">
          <el-input v-model="addForm.eNum"></el-input>
        </el-form-item>
        <el-form-item label="电话号码：">
          <el-input v-model="addForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="性别：">
          <el-input v-model="addForm.sex"></el-input>
        </el-form-item>
        <el-form-item label="年龄：">
          <el-input v-model="addForm.age"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addCateDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addFormData">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看弹出框 -->
    <el-dialog title="提示" :visible.sync="modifyCateDialogVisible" width="30%">
      <el-form label-width="100px" class="demo-ruleForm" :model="myFormData" disabled>
        <el-form-item label="用户编号：">
          <el-input v-model="myFormData.userId"></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-input v-model="myFormData.name"></el-input>
        </el-form-item>
        <el-form-item label="工号：">
          <el-input v-model="myFormData.eNum"></el-input>
        </el-form-item>
        <el-form-item label="电话号码：">
          <el-input v-model="myFormData.phone"></el-input>
        </el-form-item>
        <el-form-item label="性别：">
          <el-input v-model="myFormData.sex"></el-input>
        </el-form-item>
        <el-form-item label="年龄：">
          <el-input v-model="myFormData.age"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="modifyCateDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyCateDialogVisible=false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPersonData,
  getPersonDataThings,
  getPersonDataOne,
  getDepartmentData,
} from '../network/api.js'
import dayjs from '../utils/dayjs'
export default {
  name: 'sss',
  components: {},
  props: {},
  data() {
    //这里存数据
    return {
      addForm: {
        name: '',
        age: '',
        sex: '',
        phone: '',
        userId: '',
        eNum: '',
      },
      // 搜索框数据
      searchData: '',
      detailedFormData: {},
      // 添加表单的验证规则对象

      // 编辑弹框阀
      modifyCateDialogVisible: false,
      // diolog框开启关闭阀
      addCateDialogVisible: false,

      // 查询参数对象
      // 查询参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        keywords: '',
      },
      // 数据列表
      tableData: [],
      // 总数据条数
      total: 0,
      myFormData: {},
    }
  },
  //计算属性
  computed: {},
  //监控data中数据变化
  watch: {},
  //方法
  methods: {
    // 获取数据
    async getFormData() {
      await getPersonData({
        MaxResultCount: this.queryInfo.pagesize,
        SkipCount: (this.queryInfo.pagenum - 1) * this.queryInfo.pagesize,
      })
        .then((res) => {
          // console.log(res)
          // console.log(res.result.items, 1233)
          this.total = res.result.totalCount
          this.tableData = res.result.items
          for (let i = 0; i <= this.tableData.length; i++) {
            // console.log(this.tableData[i].phone)
            if (this.tableData[i].phone == 'string') {
              this.tableData[i].phone = ''
            }
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },

    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pagesize = newSize
      this.getFormData()
    },

    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      // console.log(newPage)
      this.queryInfo.pagenum = newPage
      this.getFormData()
    },
    // 点击添加按钮
    goAdd() {
      this.addCateDialogVisible = true
    },
    // 监听分配角色对话框的关闭事件
    setRoleDialogClosed() {
      this.addForm.userId = ''
      this.addForm.name = ''
      this.addForm.eNum = ''
      this.addForm.phone = ''
      this.addForm.sex = ''
      this.addForm.age = ''
    },
    // 点击弹窗的确定安妮
    async addFormData() {
      // console.log(123)
      this.addCateDialogVisible = false
      getPersonDataThings({
        name: this.addForm.name,
        age: this.addForm.age,
        sex: this.addForm.sex,
        phone: this.addForm.phone,
        userId: this.addForm.userId,
        eNum: this.addForm.eNum,
      })
        .then((res) => {
          // console.log(res)
          this.getFormData()
        })
        .catch((err) => {
          console.log(err)
        })
    },
    // 删除按钮
    async goDelete(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$axios
            .delete(
              'http://39.104.74.183:21028/api/services/app/Med_Members/Delete?id=' +
                id +
                ''
            )
            .then((res) => {
              // console.log(res.status)
              this.getFormData()
            })
            .catch((err) => {
              console.log(err)
            })
          this.$message({
            type: 'success',
            message: '删除成功!',
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
      // console.log(id)
    },
    // 获取查看数据
    async getFormDataId(id) {
      // console.log(id)
      this.modifyCateDialogVisible = true
      await getPersonDataOne({
        id: id,
      })
        .then((res) => {
          console.log(res.result)
          // console.log(res.result.items, 12233)
          this.myFormData = res.result
          if (this.myFormData.phone == 'string') {
            this.myFormData.phone = ''
          }

          // this.tableData.creationTime
        })
        .catch((err) => {
          console.log(err)
        })
    },
  },
  //声明周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getFormData()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
}
</script>

<style lang="less" scoped>
// .btn {
//   width: 50px;
//   height: 50px;
// }
.iptwidth {
  width: 50rem;
  margin-left: 25rem;
}
</style>>


